package in.muton.edushare.poll.pages;

import in.muton.edushare.poll.questions.NewQuestion;
import in.muton.edushare.url.URLLoader;
import in.muton.edushare.wicket.models.CayenneModel;

import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseException;

import com.edushare.common.constants.URLConstants;
import com.edushare.common.dao.PollsDAO;
import com.edushare.common.vo.PollQuestions;

public class PollEditSingleQ extends PollBase {

	private CayenneModel<PollQuestions> questionModel;

	public PollEditSingleQ(PageParameters params) {
		super(params);
		int qNum = params.getAsInteger("1", 0);
		PollQuestions pq = new PollsDAO(getSessionORMInterface())
				.getQuestionBySNo(getPollModel().getObject(), qNum);
		if(pq == null){
			throw new RestartResponseException(URLLoader
					.getPageClass(URLConstants.INTERNAL_ERROR_PATH));
		}
		questionModel = new CayenneModel<PollQuestions>(pq);
		add(new NewQuestion("editPanel", getPollModel(), questionModel, this));
	}

	@Override
	protected String getPageName() {
		return "PollEdit";
	}

}
